package com.tmeone.erpone.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tmeone.erpone.entity.Customer;
import com.tmeone.erpone.entity.JsonResult;
import com.tmeone.erpone.entity.TPar;
import com.tmeone.erpone.entity.TProduct;
import com.tmeone.erpone.service.ITParService;
import com.tmeone.erpone.service.ITProductService;
import org.beetl.ext.fn.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YJLJBD
 * @since 2021-04-22
 */
@RestController
@RequestMapping
public class TParController {

    @Autowired
    private ITParService parService;

    private TPar tPar = new TPar();

    @GetMapping("/tpar")
    public JsonResult showTpar(@RequestParam(value="current",required = false,defaultValue = "1")Integer current,@RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize){
        Page<TPar> tParPage = new Page<>(current, pageSize);
        IPage<TPar> pageTPar = parService.getPageTPar(tParPage);
        return new JsonResult(1,pageTPar);
    }
    @GetMapping("/tparByTime")
    public JsonResult tparByTime(@RequestParam(value = "time1",required = false,defaultValue = "0000-00-00 00:00:00")String time1,@RequestParam(value = "time2",required = false,defaultValue = "9999-12-59 12:59:59")String time2,@RequestParam(value="current",required = false,defaultValue = "1")Integer current,@RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize){
        Page<TPar> tparPage = new Page<>(current,pageSize);
        IPage<TPar> pageTParOnTime = parService.getPageTParOnTime(tparPage, time1, time2);
        return new JsonResult(1,pageTParOnTime);
    }
    @RequestMapping("/contractApply")
    public String toContractApply(@RequestParam(value = "id",required = false,defaultValue = "1")Integer id){

        return "contractApply";
    }
    @RequestMapping("/contractAudit")
    public String toContractAudit(@RequestParam(value = "id",required = false,defaultValue = "1")Integer id){

        return "yeOrNo";
    }

    @PutMapping("/passTpar/{id}")
    public JsonResult passTpar(@PathVariable String id){
        parService.passTpar(id);
        return new JsonResult(1,"ok");
    }
    //拒绝申请
    @PutMapping("/tparReject/{id}")
    public JsonResult rejectTpar(@PathVariable String id, @RequestBody TPar tParfront){
        System.out.println(id);
        System.out.println(tParfront.getTAprDesc());
        parService.rejectTpar(id,tParfront.getTAprDesc());
        return new JsonResult(1,"ok");
    }
    @PostMapping(value = "/addTpar/{id}")
    public JsonResult addTpar(@PathVariable String id){
        System.out.println(id);
        tPar.setTParComA(1);
        tPar.setTParComB(Integer.valueOf(id));
        tPar.setTParStatus("已申请");
        tPar.setStaffName("root");
        tPar.setTParTime(LocalDateTime.now());
        tPar.setTParRel("");
        System.out.println(tPar);
        if(parService.save(tPar)){
            return new JsonResult(1,"ok");
        }
        return new JsonResult(0,"DEFATE");
    }
    @RequestMapping("/vertificationRequest")
    public String toVertification(){
        return "vertificationRequest";
    }


}
